
#ifndef CACHE_H
#define CACHE_H

#include "common.h"
#include <map>
#include <string>


typedef struct
{
	
	std::string mPage;
	
	bool mExpires;
	std::string mExpireStr;
	time_t mExpireTime;
	time_t mLastFetchedTime;
	
} PageStruct;

typedef std::map<std::string, PageStruct> UriToPageMapping;

class Cache
{

public:

	static Cache* GetInstance() { if(mCache == NULL) mCache = new Cache;
		return mCache; }
	
	static void Destroy() { if(mCache) delete mCache; }

	bool ExistsAndValid(std::string& uri);
	std::string& GetPage(std::string& uri);

	int SetPage(const std::string& uri, const std::string& page);
	
	time_t lastmodified_time(std::string& uri);


private:

	Cache() {}

	time_t ConvertToTime(const std::string& timeStr);

	UriToPageMapping mCacheMap;

	static Cache* mCache;
		
	char mMsgBuf[MSG_BUF_SIZE];
	unsigned int mMsgBufPtr;
	bool HeaderReceived;
};

#endif // CACHE_H
